{extend name='admin@public/content'}
{block name="content"}
<style>.layui-form-label{width:210px}.layui-input-block{margin-left:230px}</style>
<div class="row">
	<div class="col-xs-12">
		<div class="col-xs-12">
		<!-- 表单 -->
		<form autocomplete="off" class="layui-form layui-box modal-form-box" action="{:url('build')}" data-auto="true" method="post">

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="must">*</span>标识名 <span class="check-tips">（请输入插件标识）</span></label>
				<div class="layui-input-block">
					<input type="text" class="text layui-input" name="info[name]" value="example">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">插件名<span class="check-tips">（请输入插件名）</span></label>
				<div class="layui-input-block">
					<input type="text" class="text layui-input" name="info[title]" value="示列">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">版本<span class="check-tips">（请输入插件版本）</span></label>
				<div class="layui-input-block">
					<input type="text" class="text layui-input" name="info[version]" value="0.1">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">作者<span class="check-tips">（请输入插件作者）</span></label>
				<div class="layui-input-block">
					<input type="text" class="text layui-input" name="info[author]" value="diygw.com">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">描述<span class="check-tips">（请输入描述）</span></label>
				<div class="layui-input-block">
					<textarea class="layui-textarea" name="info[description]">这是一个临时描述</textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">安装后是否启用</label>
				<div class="layui-input-block">
					<input type="checkbox" lay-skin="switch" name="status" value="1" checked />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">是否需要配置</label>
				<div class="layui-input-block">
					<input lay-filter="has_config" lay-skin="switch" type="checkbox" name="has_config" value="1" />
				 </div>
			</div>

			<div id="has_config" class="layui-form-item" style="display: none">
				<div class="layui-input-block margin-bottom-5">
					<textarea class="textarea layui-textarea" name="config">
						&lt;?php
						return [
							'display'=>[//配置在表单中的键名 ,这个会是config[display]
								'title'=>'是否开启随机:',//表单的文字
								'type'=>'radio',		 //表单的类型：text、textarea、checkbox、radio、select等
								'options'=>[		 //select 和radion、checkbox的子选项
									'1'=>'不显示',		 //值=>文字
									'0'=>'显示',
								],
								'value'=>'1',			 //表单的默认值
							],
						];
					</textarea>
				</div>
				<span class="check-tips has_config">自定义模板,注意：自定义模板里的表单name必须为config[name]这种，获取保存后配置的值用$data.config.name</span>
			</div>


			<div class="layui-form-item">
				<label class="layui-form-label">是否需要外部访问</label>
				<div class="layui-input-block">
					<input type="checkbox" name="has_outurl" lay-skin="switch" value="1" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">实现的钩子方法</label>
				<div class="layui-input-block">
					{volist name="Hooks" id="vo"}
						<input name="hook[]" lay-skin="primary"  title="{$vo.description}" value="{$vo.name}" type="checkbox">
					{/volist}
				</div>
			</div>
			<div class="btn-submit-group  text-center">
				<button class="layui-btn" type='submit'>确 定</button>
				<button class="layui-btn layui-btn-danger" onclick="javascript:history.back(-1);return false;">返 回</button>
			</div>
		</form>
	</div>
	</div>
</div>

	<script type="text/javascript">
        (function () {
            var form = layui.form,$=layui.$;
            form.render();
            form.on('switch(has_config)', function(data){
                $('#has_config').toggle();
            });

			$('.ajax-post_custom').click(function(){
				var target,query,form;
				var target_form = $(this).attr('target-form');
				var check_url = '{:url('checkForm')}';
				$.ajax({
				   type: "POST",
				   url: check_url,
				   dataType: 'json',
				   async: false,
				   data: $('#form').serialize(),
				   success: function(data){
						if(data.code){
							if( ($(this).attr('type')=='submit') || (target = $(this).attr('href')) || (target = $(this).attr('url')) ){
								form = $('.'+target_form);
								if ( form.get(0).nodeName=='FORM' ){
									target = form.get(0).action;
									query = form.serialize();
								}else if( form.get(0).nodeName=='INPUT' || form.get(0).nodeName=='SELECT' || form.get(0).nodeName=='TEXTAREA') {
									query = form.serialize();
								}else{
									query = form.find('input,select,textarea').serialize();
								}
								$.post(target,query).success(function(data){
									if (data.status==1) {
										if (data.url) {
											updateAlert(data.msg + ' 页面即将自动跳转~','alert-success');
										}else{
											updateAlert(data.msg + ' 页面即将自动刷新~');
										}
										setTimeout(function(){
											if (data.url) {
												location.href=data.url;
											}else{
												location.reload();
											}
										},1500);
									}else{
										updateAlert(data.msg);
									}
								});
							}
						}else{
							updateAlert(data.msg);
						}
				   }
				});

				return false;
			});
        })();
	</script>
{/block}
